package com.xiaoyaoji.admin.pojo.dto;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;


@Getter
@Setter
@ToString
public class HttpDocEntity {

    //字段名称
    private String name;
    //是否必须
    private String require;
    //默认值
    private String defaultValue;
    //描述
    private String description;
    //类型
    private String type;
    //子节点
    private List<HttpDocEntity> children;

    public String getRequire() {
        return String.valueOf("true".equalsIgnoreCase(require));
    }

    public void setRequire(String require) {
        this.require = String.valueOf("true".equalsIgnoreCase(require));
    }


    public void setType(String type) {
        if (type == null || "".equalsIgnoreCase(type)) {
            this.type = "object";
        } else if ("integer".equalsIgnoreCase(type) || "double".equalsIgnoreCase(type)) {
            this.type = "number";
        } else if ("bool".equalsIgnoreCase(type)) {
            this.type = "boolean";
        } else {
            switch (type) {
                case "string":
                case "number":
                case "boolean":
                case "object":
                case "array":
                case "array[number]":
                case "array[boolean]":
                case "array[string]":
                case "array[object]":
                case "array[array]":
                case "file":
                    this.type = type;
                    break;
                default:
                    this.type = "object";
            }
        }
    }
}
